class Solution:
    def findMedianSortedArrays(self, nums1, nums2):
        """
        :type nums1: List[int]
        :type nums2: List[int]
        :rtype: float
        求两个数组的中位数值
        """
        new_list = []
        while len(nums1) or len(nums2):
            if len(nums1)==0:
                val = nums2[0]
                nums2 = nums2[1:]
            elif len(nums2)==0:
                val = nums1[0]
                nums1 = nums1[1:]
            elif nums2[0] < nums1[0]:
                val = nums2[0]
                nums2 = nums2[1:]
            else:
                val = nums1[0]
                nums1 = nums1[1:]
            new_list.append(val)
        if len(new_list)%2 == 0:
            return (new_list[len(new_list)//2]+new_list[len(new_list)//2-1])/2
        else:
            return new_list[(len(new_list)-1)//2]

    def myAtoi(self, str):
        """
        字符串转换成整数
        :param s: str
        :return: i
        """
        i, tmp = 0, ""
        digit = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
        sign = ['+', '-', '']
        s = str.strip()
        while i < len(s):
            if (s[i] == '-' or s[i] == '+') and tmp == "":
                tmp = tmp + s[i]
                i += 1
                continue
            elif s[i] not in digit and tmp in sign:
                return 0
            elif s[i] in digit and tmp in sign:
                tmp = tmp + s[i]
                i += 1
                continue
            elif s[i] in digit:
                tmp = tmp + s[i]
                i += 1
                continue
            elif s[i] not in digit:
                break
            else:
                i += 1
        if tmp in sign:
            return 0
        else:
            tmp = int(tmp)
        if tmp >= 2**31:
            return 2**31-1
        elif tmp <= -2**31:
            return -2**31
        else:
            return tmp


sol = Solution()
nums = "+34579347fgdjfghdf"
res = sol.myAtoi(nums)
print(res)

